﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace OASystem.Controllers
{
    [App_Start.LoginFilterAtrribute]
    public class MechanismController : Controller
    {
        //
        // GET: /Mechanism/

        public ActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 角色分配
        /// </summary>
        /// <returns></returns>
        public ActionResult Role()
        {
            return View();
        }

        public ActionResult Menu(int Id)
        {
            ViewBag.RoleId = Id;
            ViewBag.authorList = BLL.MenusManager.QueryListByRoleId(Id);
            return View();
        }

        /// <summary>
        /// 职位列表
        /// </summary>
        /// <returns></returns>
        public ActionResult Position()
        {
            return View();
        }

        /// <summary>
        /// 部门列表
        /// </summary>
        /// <returns></returns>
        public ActionResult Department()
        {
            return View();
        }


        public JsonResult Query()
        {

            var list = (from i in BLL.MenusManager.QueryList().OrderByDescending(m => m.UpdateTime).ToList()
                        select new
                        {
                            id = i.Id,
                            pId = i.ParentId,
                            name = i.Name,
                            open = true
                        }).ToList<dynamic>();
            object[] array = new object[list.Count];
            for (int i = 0; i < list.Count; i++)
            {
                array[i] = list[i];
            }
            return Json(JsonConvert.SerializeObject(array));
        }

        /// <summary>
        /// 新增权限表
        /// </summary>
        /// <param name="Ids"></param>
        /// <param name="RoleId"></param>
        /// <returns></returns>
        public JsonResult InsertMenu(string Ids, int RoleId)
        {
            var result = new BLL.RoleManager().InsertRoleMenuRelation(Ids, RoleId);
            return Json(result);
        }
    }
}
